home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Trial / ConceptDraw NetDiagrammer / data1.cab / Libraries__Project_Management / Project_Management / Outline.cdb < prev    next >
Text File  |  2006-02-08  |  9KB  |  315 lines

  1. Dim intPrevTaskID As Long
  2.  
  3. Function CreateTaskObjects(recLevel As Integer, recName As String, recDuration As Double, recStart As Date, recEnd As Date, recComplete As Double, recIsPhase As Integer) As Integer
  4. On Error Goto ErrorHandle
  5.     Dim ProjectLib        As Library
  6.     Dim libTaskBar        As Master
  7.     Dim libTimeLine        As Master
  8.     Dim shapeTask        As Shape
  9.     Dim shapeTasksTitle    As Shape
  10.  
  11.     Dim dblPosS            As Double
  12.     Dim dblPosE            As Double
  13.     Dim dblPosC            As Double
  14.     Dim dblDayWidth        As Double
  15.     Dim dblCalStart        As Double
  16.  
  17.     Set ProjectLib    = thisApp.OpenLib("Project Management/Gantt Chart Shapes.cdl")
  18.     If ProjectLib = Null Then
  19.         Exit Function
  20.     End If
  21.     Set libTaskBar = ProjectLib.MasterByName("TaskBar")
  22.     If libTaskBar = Null Then
  23.         Exit Function
  24.     End If
  25.  
  26.     Set shapeTasksTitle = GetTasksTitle()
  27.     If shapeTasksTitle = Null Then
  28.         Exit Function
  29.     End If
  30.     dblDayWidth = shapeTasksTitle.CustomProp(1).Value
  31.     dblCalStart = shapeTasksTitle.CustomProp(2).Value
  32.  
  33.     Dim Y As Double
  34.     Dim shp As Shape
  35.     If intPrevTaskID = 0 Then
  36.         Y = shapeTasksTitle.GPinY + shapeTasksTitle.Height
  37.     Else
  38.         Set shp = thisDoc.ActivePage.ShapeByID(intPrevTaskID)
  39.         Y = shp.GPinY + shp.Height
  40.     End If
  41.  
  42.     shapeTasksTitle.Variable(3).X = 1
  43.     Set shapeTask = thisDoc.ActivePage.DropStamp(libTaskBar.Shape, shapeTasksTitle.GPinX, Y)
  44.     shapeTasksTitle.Variable(3).X = 0
  45.  
  46.     libTimeLine = Null
  47.     If recIsPhase = 1 Then
  48.         shapeTask.Variable(10).X = 1
  49.         shapeTask.PropertyChanged(CDPT_VARIABLE_X, 10)
  50.         Set libTimeLine = ProjectLib.MasterByName("TimeLineS3")
  51.     ElseIf recDuration = 0 Then
  52.         Set libTimeLine = ProjectLib.MasterByName("MilestoneN1")
  53.     End If
  54.     If libTimeLine <> Null Then
  55.         thisDoc.ActivePage.DropStamp(libTimeLine.Shape, shapeTask.GPinX + shapeTask.Width*0.5, shapeTask.GPinY + shapeTask.Height*0.5)
  56.     End If
  57.  
  58.     dblPosS = (recStart - dblCalStart) * dblDayWidth + shapeTask.Variable(6).X
  59.     shapeTask.ControlDot(1).X = dblPosS
  60.     dblPosE = (recEnd - dblCalStart + 1) * dblDayWidth + shapeTask.Variable(6).X
  61.     shapeTask.ControlDot(2).X = dblPosE
  62.     dblPosC = (dblPosE - dblPosS) * recComplete / 100 + dblPosS
  63.     shapeTask.ControlDot(3).X = dblPosC
  64.  
  65.     shapeTask.CustomProp(1).Value = recName
  66.     shapeTask.Variable(9).X = recLevel
  67.  
  68.     shapeTask.PropertyChanged(CDPT_CONTROL_X, 1)
  69.     shapeTask.PropertyChanged(CDPT_CONTROL_X, 2)
  70.     shapeTask.PropertyChanged(CDPT_CONTROL_X, 3)
  71.     shapeTask.PropertyChanged(CDPT_CUSTOM_VALUE, 1)
  72.     shapeTask.PropertyChanged(CDPT_VARIABLE_X, 9)
  73.  
  74.     intPrevTaskID = shapeTask.ID
  75. ErrorHandle:
  76. End Function
  77.  
  78. Sub PlaceLegend(inTaskBottomID As Integer)
  79. '    Set shapeLegend = thisDoc.ActivePage.DropStamp(libLegend.Shape, 0, 0)
  80. '    strFormula = "=ObjID" & shapeTasksTitle.ID & ".GPinX"
  81. '    shapeLegend.SetPropertyFormula(strFormula, CDPT_GPINX)
  82. '    strFormula = "=ObjID" & inTaskBottomID & ".GPinY + ObjID" & inTaskBottomID & ".Height"
  83. '    shapeLegend.SetPropertyFormula(strFormula, CDPT_GPINY)
  84. '
  85. '    shapeLegend.RecalcProperty(CDPT_GPINX)
  86. '    shapeLegend.RecalcProperty(CDPT_GPINY)
  87. End Sub
  88.  
  89. Function GetRecomendetTimeScale(startc As Double, endc As Double) As Integer
  90.     Dim period As Double
  91.     period = endc - startc
  92.     If period > 365*20 Then
  93.         GetRecomendetTimeScale = 5
  94.     ElseIf period > 365*5 Then
  95.         GetRecomendetTimeScale = 4
  96.     ElseIf period > 365 Then
  97.         GetRecomendetTimeScale = 3
  98.     ElseIf period > 365*0.5 Then
  99.         GetRecomendetTimeScale = 2
  100.     Else
  101.         GetRecomendetTimeScale = 1
  102.     End If
  103. End Function
  104.  
  105. Function LoadOutline(shapeTasksTitle As Shape, strFileName As String) As Boolean
  106. On Error Goto ErrorHandle
  107.     Dim intFileNumber        As Integer
  108.     Dim strLineData            As String
  109.     Dim intSeparatorPos        As Integer
  110.     Dim intFieldNum            As Integer
  111.     Dim intLastTaskTableID    As integer
  112.  
  113.     Dim recLevel            As Integer
  114.     Dim recIsPhase            As Integer
  115.     Dim recName                As String
  116.     Dim recDuration            As Double
  117.     Dim recStart            As Double
  118.     Dim recEnd                As Double
  119.     Dim recComplete            As Double
  120.     Dim strFormula            As String
  121.     Dim tmpCalStart            As Double
  122.     Dim tmpCalEnd            As Double
  123.     
  124.     Dim intLineNum            As Long
  125.     Dim arrayLines()        As String
  126.  
  127.     intFileNumber = FreeFile()
  128.     Open strFileName For Input As #intFileNumber
  129.     tmpCalStart    = 0
  130.     tmpCalEnd    = 0
  131.     intLineNum    = 0
  132.     Do While Not EOF(intFileNumber)
  133.         Line Input #intFileNumber, strLineData
  134.         If strLineData <> "" Then
  135.             intLineNum = intLineNum + 1
  136.             For I=1 To 4
  137.                 intSeparatorPos = InStr(strLineData, Chr(9))
  138.                 strLineData = Right(strLineData, Len(strLineData) - intSeparatorPos)
  139.             Next
  140.             intSeparatorPos = InStr(strLineData, Chr(9))
  141.  
  142.             recStart    = CDbl(Left(strLineData, intSeparatorPos - 1))
  143.             strLineData = Right(strLineData, Len(strLineData) - intSeparatorPos)
  144.  
  145.             intSeparatorPos = InStr(strLineData, Chr(9))
  146.             recEnd        = CDbl(Left(strLineData, intSeparatorPos - 1))
  147.             strLineData = Right(strLineData, Len(strLineData) - intSeparatorPos)
  148.  
  149.             If tmpCalStart > recStart OR tmpCalStart = 0 Then
  150.                 tmpCalStart = recStart
  151.             End If
  152.             If tmpCalEnd < recEnd OR tmpCalEnd = 0 Then
  153.                 tmpCalEnd = recEnd
  154.             End If
  155.         End If
  156.     Loop
  157.     Seek #intFileNumber, 0
  158.  
  159.     ReDim arrayLines(intLineNum) As String
  160.  
  161.     If intLineNum = 0 Then
  162.         shapeTasksTitle.Variable(2).Y = 0
  163.         shapeTasksTitle.PropertyChanged(CDPT_VARIABLE_Y, 2)
  164.     End If
  165.  
  166.     Dim cur_item As Long
  167.     cur_item = 1
  168.     Do While Not EOF(intFileNumber)
  169.         Line Input #intFileNumber, strLineData
  170.         If strLineData <> "" Then
  171.             arrayLines(cur_item) = strLineData
  172.             cur_item = cur_item + 1
  173.         End If
  174.     Loop
  175.     Close #intFileNumber
  176.  
  177.     Dim bChangeStart    As Boolean
  178.     Dim bChangeEnd        As Boolean
  179.     Dim dblVal            As Double
  180.     Dim bCalNotReady    As Boolean
  181.  
  182.     dblVal = shapeTasksTitle.CustomProp(2).Value
  183.     bChangeStart = tmpCalStart < dblVal OR (dblVal = 0)
  184.     dblVal = shapeTasksTitle.CustomProp(3).Value
  185.     bChangeEnd = tmpCalEnd > dblVal OR (dblVal = 0)
  186.     bCalNotReady = FindShapeByNameInGroup(shapeTasksTitle, "Calendar") = Null
  187.  
  188.     If bChangeStart OR bChangeEnd OR bCalNotReady Then
  189.         shapeTasksTitle.CustomProp(2).Value = tmpCalStart
  190.         shapeTasksTitle.CustomProp(3).Value = tmpCalEnd
  191.         shapeTasksTitle.CustomProp(4).Value = GetRecomendetTimeScale(tmpCalStart, tmpCalEnd)
  192.         BuildCalendar(shapeTasksTitle, 0)
  193.     End If
  194.  
  195.     intPrevTaskID = 0
  196.  
  197.     For I=1 To intLineNum
  198.         strLineData = arrayLines(I)
  199.         intFieldNum = 0
  200.         Do
  201.             intSeparatorPos = InStr(strLineData, Chr(9))
  202.             If intSeparatorPos > 0 Then
  203.                 strField = Trim(Left(strLineData, intSeparatorPos - 1))
  204.                 strLineData = Right(strLineData, Len(strLineData) - intSeparatorPos)
  205.             Else
  206.                 strField = Trim(strLineData)
  207.             End If
  208.             Select Case intFieldNum
  209.                 Case 0
  210.                     recLevel    = Val(strField)
  211.                 Case 1
  212.                     recIsPhase    = Val(strField)
  213.                 Case 2
  214.                     recName        = strField
  215.                 Case 3
  216.                     recDuration    = CDbl(strField)
  217.                 Case 4
  218.                     recStart    = CDbl(strField)
  219.                 Case 5
  220.                     recEnd        = CDbl(strField)
  221.                 Case 6
  222.                     recComplete    = CDbl(strField)
  223.             End Select
  224.             intFieldNum = intFieldNum + 1
  225.         Loop While intSeparatorPos > 0
  226.         intLastTaskTableID = CreateTaskObjects(recLevel, recName, recDuration, recStart, recEnd, recComplete, recIsPhase)
  227.     Next
  228.  
  229. '    PlaceLegend(intLastTaskTableID)
  230.  
  231.     LoadOutline = True
  232. ErrorHandle:
  233. End Function
  234.  
  235. Function SaveOutline(shapeTasksTitle As Shape, strFileName As String) As Boolean
  236. On Error Goto ErrorHandle
  237.     Dim intFileNumber        As Integer
  238.     Dim strLineData            As String
  239.     Dim intCurTaskID        As Integer
  240.     Dim shapeCurTask        As Shape
  241.     Dim shapeNextTask        As Shape
  242.  
  243.     Dim recLevel            As Integer
  244.     Dim recIsPhase            As Integer
  245.     Dim recName                As String
  246.     Dim recDuration            As Double
  247.     Dim recStart            As Double
  248.     Dim recEnd                As Double
  249.     Dim recComplete            As Double
  250.     Dim tmpCalStart            As Date
  251.     Dim tmpCalEnd            As Date
  252.  
  253.     intFileNumber = FreeFile()
  254.     Open strFileName For Output As #intFileNumber
  255.  
  256.     intCurTaskID = shapeTasksTitle.CustomProp(5).Value
  257.     Do While intCurTaskID <> 0
  258.         Set shapeCurTask = thisDoc.ActivePage.ShapeByID(intCurTaskID)
  259.         If shapeCurTask = Null Then
  260.             Exit Do
  261.         End If
  262.         intCurTaskID = shapeCurTask.CustomProp(5).Value
  263.  
  264.         Set shapeNextTask = thisDoc.ActivePage.ShapeByID(intCurTaskID)
  265.  
  266.         recLevel    = shapeCurTask.Variable(9).X
  267.         recIsPhase    = 0
  268.         If shapeNextTask <> Null Then
  269.             If shapeNextTask.Variable(9).X = recLevel + 1 Then
  270.                 recIsPhase = 1
  271.             End If
  272.         End If
  273.         recName        = shapeCurTask.CustomProp(1).Value
  274.         recDuration    = CDbl(shapeCurTask.CustomProp(8).Value)
  275.         recStart    = CDbl(CDate(shapeCurTask.CustomProp(6).Value))
  276.         recEnd        = CDbl(CDate(shapeCurTask.CustomProp(7).Value))
  277.         recComplete    = CDbl(shapeCurTask.CustomProp(9).Value) * 100
  278.         
  279.         strLineData = recLevel & Chr(9) & recIsPhase & Chr(9) & recName & Chr(9) & recDuration & Chr(9) & recStart & Chr(9) & recEnd & Chr(9) & recComplete
  280.         Print #intFileNumber, strLineData
  281.     Loop
  282.  
  283.     Close #intFileNumber
  284.     SaveOutline = True
  285. ErrorHandle:
  286. End Function
  287.  
  288. Function ClearPage(shp As Shape) As Integer
  289.     ClearPage = 1
  290.     For I=thisDoc.ActivePage.ShapesNum() To 1 Step -1
  291.         If thisDoc.ActivePage.Shape(I).Name = "TimeLineS" OR thisDoc.ActivePage.Shape(I).Name = "TaskBar" Then
  292.             thisDoc.ActivePage.RemoveShape(I)
  293.         End If
  294.     Next
  295. End Function
  296.  
  297. Declare Function PPTaskPropDlg Lib "CDWizards" (ByRef strFileName As String) As Long
  298. Declare Function SelectTmpFile Lib "CDWizards" (ByRef sFileName As String, ByVal iLendth As Long) As Long
  299.  
  300. Function DoShowWizard(shp As Shape) As Integer
  301. On Error Goto ErrorHandle
  302.     Dim strFileName As String
  303.     strFileName = Space(1024)
  304.     SelectTmpFile(strFileName, 1024)
  305.     SaveOutline(shp, strFileName)
  306.     res = PPTaskPropDlg(strFileName)
  307.     If res <> -1 Then
  308.         ClearPage(Null)
  309.         thisDoc.StartRebuild()
  310.         LoadOutline(shp, strFileName)
  311.         thisDoc.EndRebuild()
  312.     End If
  313. ErrorHandle:
  314. End Function
  315.